package com.woniu.shop.controller;


import com.woniu.entity.Result;
import com.woniu.entity.ResultCode;
import com.woniu.shop.entity.dto.ComplaintDTO;
import com.woniu.shop.entity.dto.StoreServiceDTO;
import com.woniu.shop.pojo.Complaint;
import com.woniu.shop.service.IComplaintService;
import com.woniu.shop.service.impl.ComplaintServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户投诉表 前端控制器
 * </p>
 *
 * @author malei
 * @since 2023-02-18
 */
@Api(tags = "投诉控制器")
@RestController
@RequestMapping("/complaint")
public class ComplaintController {

    @Autowired
    private IComplaintService complaintService;

    @ApiOperation("新增门店投诉")
    @PostMapping("/add")
    public Result addComplaint(@RequestBody ComplaintDTO complaintDTO) {
        return complaintService.addComplaint(complaintDTO);
    }

    @ApiOperation("查看门店投诉列表")
    @GetMapping("/queryComplaintByStatus/{shopID}/{status}")
    public Result queryComplaintByStatus(@PathVariable String shopID,@PathVariable String status){
        return complaintService.queryComplaintByStatus(shopID,status);
    }

    @ApiOperation("根据ID查询投诉详情")
    @GetMapping("/queryById/{id}")
    public Result queryById(@PathVariable String id){
        Complaint complaint = complaintService.getById(id);
        if (complaint!= null){
            return Result.ok(complaint);
        }
        return Result.error(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMessage());
    }
    @ApiOperation("根据ID删除投诉详情")
    @DeleteMapping ("/removeById/{id}")
    public Result removeById(@PathVariable String id){
        boolean flag = complaintService.removeById(id);
        if (flag) {
            return Result.ok();
        }
        return Result.error(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMessage());
    }

    @ApiOperation("根据ID回复投诉详情")
    @GetMapping  ("/removeById/{id}/{message}")
    public Result replyComplaint(@PathVariable String id,@PathVariable String message){
        return complaintService.replyComplaint(id,message);
    }

}
